<template>
  <div>
    <my-content :comment="comment" @change="changeCommer"></my-content>
    <reply :type="type" :name="oldComment" @submit="addComment"></reply>
  </div>
</template>
<script>
import reply from '@/components/new/Reply'
import MyContent from '@/components/new/MyContent';

export default {
  name: "Diagnose",
  components:{reply, MyContent},
  data () {
    return {
      commenter: "session",
      type: 0,
      oldComment: null,
      chosedIndex: -1,
      article: {
        title: "新生牛犊注意事项",
        time: "2021-03-09",
        read: 50,
        content: ""
      },
      comment: [
        {
          name: "zjc",
          time: "2021-01-01",
          content: "ssssss",
          reply: [
            {
                responder: "傲娇的",    //评论者
                reviewers: "有毒的黄同学",         //被评论者
                time: "2016-09-05",
                content: "你说得对"
            },
            {
                responder: "傲娇的",    //评论者
                reviewers: "有毒的黄同学",         //被评论者
                time: "2016-09-05",
                content: "你说得对"
            }
          ]
        }
      ]
    };
  },
  methods: {
    addComment(data){
      console.log("回复评论")
      if(this.type == 0){
        this.comment.push({
          name: 'session',
          // time: getTime(),
          content: data,
          reply: []
        })
      }else if(this.type == 1){
        this.comment[this.chosedIndex].reply.push({
          responder: 'session',
          reviewers: this.comment[this.chosedIndex].name,
          // time: getTime(),
          content: data
        })
        this.type = 0
      }
    },
    changeCommer(name ,index){
      this.oldComment = name;
      this.chosedIndex = index;
      this.type = 1;
    },
    canelCommit(){
      this.type = 0;
    }
  }
}
</script>
<style lang="less" scoped>
</style>